# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file '获取文件信息.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2 import QtCore, QtGui, QtWidgets
import sys
import os
import time

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.textBrowser = QTextBrowser(self.centralwidget)
        self.textBrowser.setObjectName(u"textBrowser")
        self.textBrowser.setGeometry(QRect(140, 160, 451, 261))
        self.widget = QWidget(self.centralwidget)
        self.widget.setObjectName(u"widget")
        self.widget.setGeometry(QRect(140, 90, 451, 61))
        self.horizontalLayout = QHBoxLayout(self.widget)
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.label = QLabel(self.widget)
        self.label.setObjectName(u"label")

        self.horizontalLayout.addWidget(self.label)

        self.lineEdit = QLineEdit(self.widget)
        self.lineEdit.setObjectName(u"lineEdit")

        self.horizontalLayout.addWidget(self.lineEdit)

        self.pushButton = QPushButton(self.widget)
        self.pushButton.setObjectName(u"pushButton")

        # 为按钮添加信号与槽
        self.pushButton.clicked.connect(self.getInfo)

        self.horizontalLayout.addWidget(self.pushButton)

        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setObjectName(u"menubar")
        self.menubar.setGeometry(QRect(0, 0, 800, 26))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName(u"statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)
    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u83b7\u53d6\u6587\u4ef6\u4fe1\u606f", None))
        self.label.setText(QCoreApplication.translate("MainWindow", u"\u9009\u62e9\u8def\u5f84\uff1a", None))
        self.pushButton.setText(QCoreApplication.translate("MainWindow", u"\u9009\u62e9", None))

    def getInfo(self):
        file = QFileDialog()                       # 创建文件对话框
        file.setDirectory('E:\\')                  # 设置初始路径为C盘
        if file.exec_():                           # 判断是否选择了文件
            filename = file.selectedFiles()[0]     # 获取选择的文件
            self.lineEdit.setText(filename)        # 将选择的文件显示在文本框中
            fileinfo = os.stat(filename)           # 获取文件信息
            self.textBrowser.setText('文件完整路径：' + os.path.abspath('filename')
                                     + '\n文件大小：' + str(fileinfo.st_size) + '字节'
                                     + '\n最后一次访问时间：'
                                     + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(fileinfo.st_atime))
                                     + '\n最后一次修改时间：'
                                     + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(fileinfo.st_mtime))
                                     + '\n最后一次状态变化时间：'
                                     + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(fileinfo.st_ctime)))


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
